package com.cskaoyan.gateway.controller.shopping;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.IContentService;
import com.mall.shopping.IHomeService;
import com.mall.shopping.IProductCateService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.dto.AllProductCateRequest;
import com.mall.shopping.dto.AllProductCateResponse;
import com.mall.shopping.dto.HomePageResponse;
import com.mall.shopping.dto.NavListResponse;
import com.mall.user.annotation.Anoymous;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @program: cs-mall
 * @description:
 * @author: Mr.Mengmeng
 * @create: 2021-04-21 14:46
 **/

// 商品模块
@Slf4j
@RestController
@RequestMapping("/shopping")
@Anoymous
public class ShoppingController {

//    @Reference(timeout = 3000, check = false)
    @Reference(check = false)
IHomeService homeService;
    @Reference(check = false)
    IContentService contentService;
    @Reference(check = false)
    IProductCateService productCateService;

    @ApiOperation("主页显示接口")
    @GetMapping("homepage")
    public ResponseData homePage() {

        HomePageResponse response = homeService.homepage();
        if (response.getCode().equals(ShoppingRetCode.SUCCESS.getCode())) {
            return new ResponseUtil().setData(response.getPanelContentItemDtos());
        }
        return new ResponseUtil().setErrorMsg(response.getMsg());
    }

    @ApiOperation("导航栏显示")
    @GetMapping("navigation")
    public ResponseData navigation() {
        NavListResponse response = contentService.queryNavList();
        if (response.getCode().equals(ShoppingRetCode.SUCCESS.getCode())) {
            return new ResponseUtil().setData(response.getPannelContentDtos());
        }
        return new ResponseUtil().setErrorMsg(response.getMsg());
    }

    @ApiOperation("列举所有商品种类")
    @GetMapping("categories")
    @ApiImplicitParam(name = "sort", value = "升序降序标记", paramType = "query", required = false)
    public ResponseData categories(String sort) {
        // name=”参数名“，value=”参数的解释“，required=”参数是否必须传“,paramType="参数放在哪个地方"，
        // dataType=”参数类型“，默认为String
        AllProductCateRequest request = new AllProductCateRequest();
        request.setSort("null".equals(sort) ? "asc" : "desc");
        AllProductCateResponse response = productCateService.getAllProductCate(request);

        if (response.getCode().equals(ShoppingRetCode.SUCCESS.getCode())) {
            return new ResponseUtil().setData(response.getProductCateDtoList());
        }
        return new ResponseUtil().setErrorMsg(response.getMsg());
    }
}

//@RestController
//@RequestMapping("user")
//class Login{
//
//    @GetMapping("login")
//    public ResponseData login(){
//
//        return new  ResponseUtil().setData(SysRetCodeConstants.SUCCESS);
//    }
//}
